package com.mystudyCode.controller;

import com.mystudyCode.domain.Student;
import com.mystudyCode.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author lihai
 * @Description
 * @create 2022/2/4 -23:45
 */
@Controller
@RequestMapping("/student")
public class studentController {

    @Resource
    private StudentService service;

    @RequestMapping("/add.do")
    public ModelAndView addStudent(Student stu){
        String msg = "注册失败！";
        ModelAndView mv = new ModelAndView();

        //调用service
        int num = service.addStudents(stu);
        if(num>0){
            msg = "注册【"+stu.getName()+"】成功！";
        }
        mv.addObject("msg",msg);
        mv.setViewName("result");
        return mv;
    }
}
